package com.xiaomeng.singleton.type5;

public class SingletonTest05 {
    public static void main(String[] args) {

    }
}
// 双重检查模式(懒汉式，同步方法)
class Singleton {
    private static volatile Singleton instance;
    private Singleton() {}
    // 加入双重检查代码，解决线程安全问题，同事解决懒加载问题
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }



}


